package org.example.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.example.utils.AuthUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.mapper.MemberMapper;
import org.example.domain.Member;
import org.example.service.MemberService;

@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService{

    @Autowired
    private MemberMapper memberMapper;


    @Override
    public Member modifyMemberInfoByOpenId(Member member) {
        String openId = AuthUtils.getMemberOpenId();

        memberMapper.update(member ,new LambdaQueryWrapper<Member>()
                .eq(Member::getOpenId, openId)) ;

        Member memberInfo = memberMapper.selectOne(new LambdaQueryWrapper<Member>()
                .eq(Member::getOpenId, openId)
                .select( Member::getNickName, Member::getPic));
        // 返回更新后的完整用户信息
        return memberInfo;
    }

    @Override
    public Member checkMemberInfoByOpenId(String openId) {

        // 根据openId查询用户信息
        return memberMapper.selectOne(new LambdaQueryWrapper<Member>()
                .eq(Member::getOpenId, openId)
                .select( Member::getNickName, Member::getPic));

    }

}

